home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / SIZE.CPP < prev    next >
C/C++ Source or Header  |  1994-06-05  |  5KB  |  197 lines

  1. // SIZE.CPP                                  1          1    6666
  2. // Dave Harris                                11         11   6
  3. // Compiled using Borland C++ ver 3.1       1 1        1 1   6666
  4. // 03-03-94                                  1     ..   1   6   6
  5. //                                           11111 .. 11111  666
  6. ////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "au.hpp"
  9.  
  10. #define PROGRAM "SIZE"    // Name of module
  11. /*********************************************************************/
  12.  
  13. #define SELF  MAX_TYPES
  14. #define TOTAL MAX_TYPES +1
  15.  
  16. typedef struct
  17. {
  18.     char non_arcs;                      // include the non-arcs
  19.     int first;
  20.  
  21.     long uncomp_size[MAX_TYPES+2],
  22.          comp_size[MAX_TYPES+2],
  23.          count[MAX_TYPES+2],
  24.          inside_count[MAX_TYPES+2];
  25. } SIZE_INFO;
  26.  
  27. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  28. static void set_stats(AU *au, char *file_name, int type, long uncomp,
  29.                       long comp, int inside)
  30. {
  31.     SIZE_INFO *in = (SIZE_INFO *)au->info;
  32.  
  33.     printf("%-15s", file_name);
  34.     if (uncomp < 0)
  35.     {
  36.         add_to_bad_list(au, au->source_directory, file_name);
  37.         return;
  38.     }
  39.     in->uncomp_size[type]+=uncomp;
  40.     in->comp_size[type]+=comp;
  41.     in->count[type]++;
  42.     in->inside_count[type]+=inside;
  43.  
  44.     printf("%11ld %11ld, %s%%  %d\n", comp, uncomp, percent_string(uncomp,comp),
  45.            inside);
  46. }
  47. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  48. static long size_of_archive(AU *au, int *inside, ARC_HANDLE *arc_handle)
  49. {
  50.     ARC_RECORD record;
  51.     int ret_code;
  52.     long unpacked_sum=0;
  53.  
  54.     *inside = 0;
  55.  
  56.     for (;;)
  57.     {
  58.         ret_code = arc_handle->get_record(au, &record);
  59.         if (ret_code == EOF)
  60.             break;
  61.         else if (ret_code == -2)
  62.             return -2;
  63.         else if (ret_code == -3)
  64.             return arc_handle->file_length();
  65.         unpacked_sum += record.unpacked_size;
  66.         (*inside)++;
  67.     }
  68.     return unpacked_sum;
  69. }
  70. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  71. static int size(AU *au, char *file_name)
  72. {
  73.     ARC_HANDLE arc_handle;
  74.     int inside;
  75.     long comp;
  76.     long uncomp;
  77.     SIZE_INFO *in = (SIZE_INFO *)au->info;
  78.  
  79.     check_for_key();
  80.  
  81.     arc_handle.init(au, file_name);
  82.     comp = arc_handle.file_length();
  83.  
  84.     switch (arc_handle.type)
  85.     {
  86.         case NONARC:
  87.             if (in->non_arcs == ON)
  88.                  set_stats(au, file_name, NONARC, comp, comp, 1);
  89.             break;
  90.         default:
  91.             uncomp = size_of_archive(au, &inside, &arc_handle);
  92.             set_stats(au, file_name, (arc_handle.is_self ? SELF : arc_handle.type),
  93.                       uncomp, comp, inside);
  94.             break;
  95.     }
  96.     arc_handle.deinit(au);
  97.     return 0;
  98. }
  99. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  100. static void show_stats(AU *au, char *string, int type)
  101. {
  102.     SIZE_INFO *in = (SIZE_INFO *)au->info;
  103.  
  104.     if (in->comp_size[type]==0 && in->uncomp_size[type]==0)
  105.         return;
  106.  
  107.     if (!in->first)
  108.         printf("+---------+----------+----------+------------+---------------+---------+\n");
  109.     else
  110.         in->first = FALSE;
  111.  
  112.     printf("| %-6s  | %7ld  | %7ld  | %10ld |  %10ld   | %s  |\n", string,
  113.            in->count[type], in->inside_count[type], in->comp_size[type],
  114.            in->uncomp_size[type],
  115.            percent_string(in->uncomp_size[type], in->comp_size[type]));
  116.  
  117.     return;
  118. }
  119. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  120. static BYTE parse_comm_line(AU *au, char option, char *, PARSE_TYPE type)
  121. {
  122.     SIZE_INFO *in = (SIZE_INFO *)au->info;
  123.  
  124.     switch (type)
  125.     {
  126.     case PARSE_PARAM_OPTION:
  127.         switch (option)
  128.         {
  129.         case 'X':
  130.             au->self_extracts = get_value(au, OFF | ON);
  131.             break;
  132.         case 'N':
  133.             in->non_arcs = get_value(au, OFF | ON);
  134.             break;
  135.         case '?':
  136.             au_standard_opt_header(au, "SIze",
  137.                 "@?3-X@?Hon|off         self eXtracts\n"
  138.                 "@?3-N@?Hon|off         process Non-Arcs\n");
  139.             exit(0);
  140.         default:
  141.             au_invalid_option(au, PROGRAM, option);
  142.         }
  143.         return TRUE;
  144.     }
  145.     return FALSE;
  146. }
  147. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  148. int main_size(AU *au, int argc, char *argv[])
  149. {
  150.     SIZE_INFO *in;
  151.  
  152.     in = new SIZE_INFO;
  153.     memset(in, '\0', sizeof(SIZE_INFO));
  154.     au->info = in;
  155.     in->non_arcs = ON;
  156.     in->first = TRUE;
  157.  
  158.     au->allow_rename = FALSE;
  159.  
  160.     ReadGlobalCFGInfo(au, au->cfg_file, PROGRAM, NULL);
  161.  
  162.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  163.     process_files(au, size);
  164.  
  165.     for (int i=0 ; i<MAX_TYPES ; i++)
  166.     {
  167.         in->comp_size[TOTAL]   += in->comp_size[i];
  168.         in->uncomp_size[TOTAL] += in->uncomp_size[i];
  169.         in->count[TOTAL]       += in->count[i];
  170.         in->inside_count[TOTAL]+= in->inside_count[i];
  171.     }
  172.     if (in->comp_size[TOTAL]!=0)
  173.     {
  174.         printf("\n"
  175.                "+=========+==========+==========+============+===============+=========+\n"
  176.                "| Archive |   File   |  Inside  |   Total    |     Total     | Percent |\n"
  177.                "|   Type  |   Count  |   Count  | Compressed |  UnCompressed | Savings |\n"
  178.                "+=========+==========+==========+============+===============+=========+\n");
  179.  
  180.         for (i = 1; i < MAX_TYPES; i++)
  181.             show_stats(au, au->package[i].extension, i);
  182.  
  183.         show_stats(au, "SlfExt", SELF);
  184.         show_stats(au, "NonArc", NONARC);
  185.  
  186.         printf("+=========+==========+==========+============+===============+=========+\n");
  187.         in->first = TRUE;
  188.         show_stats(au, "Total", TOTAL);
  189.         printf("+=========+==========+==========+============+===============+=========+\n");
  190.     }
  191.     else
  192.         printf("\nNo Stats Available\n");
  193.  
  194.     return 0;
  195. }
  196.  
  197.